// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Main
{
	using System;
    using System.Diagnostics;
	using System.Drawing;
	using System.IO;
	using System.Reflection;
	using System.Windows.Forms;

	public sealed partial class About : Form
	{
		#region Fields

		private StreamReader sr;

		#endregion Fields

		#region Constructors

		public About()
		{
			InitializeComponent();
			creditsRTB.GotFocus += txt_GotFocus;
			txtLicense.GotFocus += txt_GotFocus;
			Text += Assembly.GetExecutingAssembly().GetName().Version.ToString();
			lblVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
			pbLogo.ImageLocation = CE.Classes.Constants.AboutImage;
			pbLogo.Width = 520;
			pbLogo.Height = 110;
			LoadCreditsFile();
		}

		#endregion Constructors

		#region Methods

		private void About_FormClosing(object sender, FormClosingEventArgs e)
		{
			timer1.Dispose();
			Dispose(true);
		}

		private void About_Load(object sender, EventArgs e)
		{
			timer1.Start();
		}

		private void LoadCreditsFile()
		{
			creditsRTB.LoadFile(CE.Classes.Constants.CreditsFile, RichTextBoxStreamType.RichText);
		}

		private void btnClose_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			Close();
		}

		private void rTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
		{
			Process.Start(e.LinkText);
		}

		private void tabControl1_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
				Close();
		}

		private void tabControl1_Selected(object sender, TabControlEventArgs e)
		{
			if (tabControl1.SelectedTab.Name == "tabPage2") {
				sr = new StreamReader(CE.Classes.Constants.LicenseFile);
				txtLicense.Text = sr.ReadToEnd();
				sr.Close();
			}
		}

		private void timer1_Tick(object sender, EventArgs e)
		{
			if (tabControl1.SelectedTab.Name == "tabPage1") {
				creditsRTB.Visible = true;
				creditsRTB.Location = creditsRTB.Location.Y > (creditsRTB.Height * -1) ?
				        new Point(creditsRTB.Location.X, creditsRTB.Location.Y - 1) : new Point(3, 154);
			} else {
				txtLicense.Location = txtLicense.Location.Y > (txtLicense.Height * -1) ?
				                      new Point(txtLicense.Location.X,txtLicense.Location.Y - 1) : new Point(6, 143);
			}
		}

		private void txt_GotFocus(object sender, EventArgs e)
		{
			tabControl1.Focus();
		}

        private void About_Paint(object sender, PaintEventArgs e)
        {
            Program.MakeBackgroundGradient(e.Graphics, this);
        }

		#endregion Methods
	}
}